import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup} from "@angular/forms";
import {Globals} from "../../../globals";
import {PageHelper} from "../../../utils/page-helper-model";
import {MyDateModel} from "../../../models/my-date.model";
import {ApiUrl} from "../../../config/api-url";
import {BaseService} from "../../../shared/service/base.service";

@Component({
  selector: 'app-stmt-result',
  templateUrl: './stmt-result.component.html',
  styleUrls: ['./stmt-result.component.less']
})
export class StmtResultComponent implements OnInit {
  // 模态框表单
  formModel: FormGroup;
  isMobile = Globals.isMobile();
  listOfData: any;
  // 分页
  pageHelper: PageHelper = new PageHelper;
  // 开始日期类型
  startDateTimeType: string = 'start';
  // 结束日期类型
  endDateTimeType: string = 'end';
  // 开始日期
  startDateTime: Date;
  // 结束日期
  endDateTime: Date;
  // 运营商
  userList: [];
  // 门店
  merchantStoreList: [];
  // 支付渠道
  payCompanyList: [];

  constructor(public baseService: BaseService, private fb: FormBuilder) {
  }

  ngOnInit(): void {
    this.buildForm();
    this.getAllUserOfName();
    this.findAllMerchantStoreByUserInfo();
    this.findPayCompanyList();
  }

  buildForm() {
    this.formModel = this.fb.group({
      userId: ['', []],
      merchantStoreId: ['0', []],
      code: ['0', []],
      payStatus: ['-1', []],
      merchantId: ['', []],
    });
  }

  getAllUserOfName() {
    this.baseService.get(ApiUrl.UserUrl + '/getAllUserOfName').subscribe(data => {
      if (data.status == 0) {
        this.userList = data.data;
      } else {
        this.baseService.layer.messageError(data.msg);
      }
    });
  }


  findAllMerchantStoreByUserInfo() {
    let userId = this.formModel.get("userId").value;
    if (userId == null) {
      userId = '';
    }
    this.baseService.get(ApiUrl.MerchantStoreUrl + '/findAllMerchantStoreByUserInfo?userId=' + userId).subscribe(
      data => {
        if (data.status == 0) {
          this.merchantStoreList = data.data;
        } else {
          this.baseService.layer.messageError(data.msg);
        }
      }
    );
  }

  gainUserId($event: any) {
    this.findAllMerchantStoreByUserInfo();
  }

  submitForm() {

  }

  nzPageIndexChange($event: number) {

  }

  // 将开始、结束时间往外抛
  outDateTime($event: MyDateModel) {
    /**
     * date: Fri Mar 19 2021 23:59:06 GMT+0800 (中国标准时间) {}
     * type: "end"
     */
    if ($event.type == 'start') {
      this.startDateTime = $event.date;
    } else if ($event.type == 'end') {
      this.endDateTime = $event.date;
    }
  }

  findPayCompanyList() {
    this.baseService.get(ApiUrl.payCompanyUrl + '/findPayCompanyList').subscribe(res => {
      if (res.status == 0) {
        this.payCompanyList = res.data;
      } else {
        this.baseService.layer.messageError(res.msg);
      }
    });
  }
}
